#include <iostream>
using namespace std;
class MyStack
{
public:
MyStack(int N)
{
      m_N   = N;
      m_top = m_N;
      m_data = new int[m_N];
};
~MyStack()
{
        delete[] m_data;
};
public:
bool IsFull()
{
    if(!m_top)
    {
        return true;
    }
    else
    {
        return false;
    }

};
bool IsEmpty()
{
    if(m_top==m_N)
    {
        return true;
    }
    else
    {
        return false;
    }
};
void Push(int item=0)
{
    *m_data=item;
    m_top--;
    m_data++;
};
int  pop()
{
    m_top++;
    return *(--m_data);
};
private:
         int       m_N;
         int       m_top;
       int   *   m_data;
};

class MyQueue
{
public:
MyQueue(int sizeOut,int sizeIn):m_out(sizeOut),m_in(sizeIn)
{
};
~MyQueue(void){};
public:
bool IsEmpty()
{
    if(this->m_in.IsEmpty()&&this->m_out.IsEmpty())
    {
        return true;
    }
    else
    {
        return false;
    }
};
bool IsFull()
{
    if(m_in.IsFull()&&!m_out.IsEmpty())
    {
        return true;
    }
    else
    {
        return false;
    }
};
void push(int data)
{
        if (!m_in.IsFull())
       {
             m_in.Push(data);
       }else{
              if (m_out.IsEmpty())
             {
                    while(!m_in.IsEmpty())
                   {
                           if (!m_out.IsFull())
                          {
                              m_out.Push(m_in.pop());
                          }
                   }
                  m_in.Push(data);
            }
        }
};
int  pop()
{
              if (!m_out.IsEmpty())
             {
                    return m_out.pop();
             }else{
             while(!m_in.IsEmpty())
             {
                    m_out.Push(m_in.pop());
             }
            return m_out.pop();
      }
};
private:
      MyStack m_out;
      MyStack m_in;
};

int main(int argc, char* argv[])
{
       MyQueue myQueue(3,2);
       char buf[200];
      cin.getline(buf,200);
       char * pbuf = buf;
       while(*pbuf != 'T')
     {
                if (*pbuf == 'A')
                {
                      pbuf++;
                      while(*pbuf < '0' || *pbuf >'9')
                      {
                              if (*pbuf == 'T')
                             {
                                    return 0;
                             }
                             pbuf++;
                      }
                      if (!myQueue.IsFull())
                     {
                             myQueue.push(*pbuf - '0');
                     }
                    else{
                            cout<<"ERROR:Full"<<endl;
                     }
                     pbuf++;
               }else if (*pbuf == 'D')
              {
                     if (!myQueue.IsEmpty())
                    {
                            cout<<myQueue.pop()<<endl;
                    }else{
                         cout<<"ERROR:Empty"<<endl;
                    }
                    pbuf++;
               }else{
                   pbuf++;
             }
       }
      return 0;
}